const express = require('express');
const weatherController = require('../controllers/weatherController');
const authController = require('../controllers/authController');

const router = express.Router();

// 城市搜索API - 与和风天气API路径保持一致
router.get('/geo/v2/city/lookup', weatherController.searchCity);
// 向后兼容的路由
router.get('/city/lookup', weatherController.searchCity);

// 获取热门城市 - 与和风天气API路径保持一致
router.get('/geo/v2/city/top', weatherController.getPopularCityWeather);
// 向后兼容的路由
router.get('/city/top', weatherController.getPopularCityWeather);

// 获取多个城市天气 (接受POST请求体中的城市列表)
router.post('/multi', weatherController.getMultiCityWeather);

// 创建/更新天气数据 (仅管理员)
router.post('/', authController.protect, authController.restrictTo('admin'), weatherController.updateWeather);

// 获取特定城市的天气预报详情
router.get('/forecast/:city/:province', weatherController.getForecastDetail);

// 获取特定城市的天气数据 (必须放在最后，因为它是通配符路由)
router.get('/:city/:province', weatherController.getWeather);

module.exports = router; 